package com.fc.test.service;

import java.util.List;

import com.fc.test.mapper.auto.TAbbMemberMapper;
import com.fc.test.model.auto.TAbbMember;
import com.fc.test.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.Convert;
import com.fc.test.mapper.auto.TAbbFankuiMapper;
import com.fc.test.model.auto.TAbbFankui;
import com.fc.test.model.auto.TAbbFankuiExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;

/**
 * 意见反馈表Service
* @Title: TAbbFankuiService.java 
* @Package com.fc.test.entity 
* @author fuce
* @email 87766867@qq.com
* @date 2019-08-28 17:52:22  
 */
@Service
public class TAbbFankuiService implements BaseService<TAbbFankui, TAbbFankuiExample>{
	@Autowired
	private TAbbFankuiMapper tAbbFankuiMapper;

	@Autowired
	private TAbbMemberMapper memberMapper;

	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<TAbbFankui> list(Tablepar tablepar,String name){
	        TAbbFankuiExample testExample=new TAbbFankuiExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andUsernameLike("%"+name+"%");
	        }

	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<TAbbFankui> list= tAbbFankuiMapper.selectByExample(testExample);
	        PageInfo<TAbbFankui> pageInfo = new PageInfo<TAbbFankui>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
		List<String> lista=Convert.toListStrArray(ids);
		TAbbFankuiExample example=new TAbbFankuiExample();
		example.createCriteria().andIdIn(lista);
		return tAbbFankuiMapper.deleteByExample(example);
	}


	@Override
	public TAbbFankui selectByPrimaryKey(String id) {

		return tAbbFankuiMapper.selectByPrimaryKey(id);
	}


	@Override
	public int updateByPrimaryKeySelective(TAbbFankui record) {
		return tAbbFankuiMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 添加
	 */
	@Override
	public int insertSelective(TAbbFankui record) {
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
		return tAbbFankuiMapper.insertSelective(record);
	}










	@Override
	public int updateByExampleSelective(TAbbFankui record, TAbbFankuiExample example) {

		return tAbbFankuiMapper.updateByExampleSelective(record, example);
	}


	@Override
	public int updateByExample(TAbbFankui record, TAbbFankuiExample example) {

		return tAbbFankuiMapper.updateByExample(record, example);
	}

	@Override
	public List<TAbbFankui> selectByExample(TAbbFankuiExample example) {

		return tAbbFankuiMapper.selectByExample(example);
	}


	@Override
	public long countByExample(TAbbFankuiExample example) {

		return tAbbFankuiMapper.countByExample(example);
	}


	@Override
	public int deleteByExample(TAbbFankuiExample example) {

		return tAbbFankuiMapper.deleteByExample(example);
	}


	public int submitFankui(String userid,String content){
		TAbbMember member = memberMapper.selectByPrimaryKey(userid);

		TAbbFankui fankui = new TAbbFankui();
		fankui.setId(SnowflakeIdWorker.getUUID());
		fankui.setContent(content);
		fankui.setCreattime(DateUtil.getCurrentDateTimeStr());
		fankui.setUserid(userid);
		fankui.setUsername(member.getNicename());
		int flag = tAbbFankuiMapper.insert(fankui);

		return flag;
	}



}
